<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>src\cmpage\model\area.js</title>
  
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="stylesheet" href="../assets/vendor/bootstrap/css/bootstrap.min.css">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
</head>
<body class="yui3-smart">
 <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
               <a class="navbar-brand mainlogo" href="/static/doc/index.html">
             
            <img alt="" src="../assets/css/logo.png" title="">
            
                
          </a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                 <ul class="nav navbar-nav">
                    
                    <li><a href="/home/index/index">首页</a>
                    </li>
                    
                    <li><a href="/static/doc/index.html">文档</a>
                    </li>
                    
                    <li><a href="/admin/index/index">演示</a>
                    </li>
                    
                    <li><a href="/home/index/log">日志</a>
                    </li>
                    
                </ul>
               <div class="navbar-form navbar-right filterAPi" autocomplete="off">
                <input type="text" id='txtSearchAPI' class="form-control search-query" placeholder="Search for API" />
                 <ul id="filterList" class="filterItems dropdown-menu" role="menu"></ul>
                </div>
            </div>
        </div>
    </nav>
    <div id="sidebar">
    <h3>Modules/Classes</h3>
        <div id="api-tabview-filter">
            <input id='txtSearch' type="search" class="form-control" placeholder="Type to filter Modules/Classes">
        </div>
        <dl id="sidebar_list">
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/admin.controller.html">admin.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/admin.controller.base.html">admin.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.code.html">admin.controller.code</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.index.html">admin.controller.index</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.mob.html">admin.controller.mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/admin.model.html">admin.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/admin.model.code.html">admin.model.code</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.code_list.html">admin.model.code_list</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.code_lookup.html">admin.model.code_lookup</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.groupuser.html">admin.model.groupuser</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.groupuser_add.html">admin.model.groupuser_add</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.log.html">admin.model.log</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.login.html">admin.model.login</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.privilege.html">admin.model.privilege</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.teamuser.html">admin.model.teamuser</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.teamuser_add.html">admin.model.teamuser_add</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.user.html">admin.model.user</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.controller.html">cmpage.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.controller.base.html">cmpage.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.mob.html">cmpage.controller.mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.module.html">cmpage.controller.module</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.page.html">cmpage.controller.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.utils.html">cmpage.controller.utils</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.logic.html">cmpage.logic</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.logic.page.html">cmpage.logic.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.model.html">cmpage.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.model.area.html">cmpage.model.area</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.base.html">cmpage.model.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.file_list.html">cmpage.model.file_list</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page.html">cmpage.model.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_excel.html">cmpage.model.page_excel</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_lookup.html">cmpage.model.page_lookup</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_mob.html">cmpage.model.page_mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.utils.html">cmpage.model.utils</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.cmpage_global.html">cmpage.cmpage_global</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.cmpage_global_flow.html">cmpage.cmpage_global_flow</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/demo.model.html">demo.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.model.proc_assign.html">flow.model.proc_assign</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.appr.html">cmpage.model.appr</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.proc.html">flow.model.proc</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task.html">flow.model.task</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task_act.html">flow.model.task_act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task_act_appr.html">flow.model.task_act_appr</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/flow.controller.html">flow.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.controller.act.html">flow.controller.act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.base.html">flow.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.proc.html">flow.controller.proc</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.task.html">flow.controller.task</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.task_act.html">flow.controller.task_act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/flow.model.html">flow.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.model.act.html">flow.model.act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.act_path.html">flow.model.act_path</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
        </dl>
</div>
   
    <div class="stdoc-content">
        <!--     <form id="options-form" class="form-inline pull-right">
        Show:
        <label for="api-show-inherited" class="checkbox">
            <input type="checkbox" id="api-show-inherited" checked>
            Inherited
        </label>

        <label for="api-show-protected" class="checkbox">
            <input type="checkbox" id="api-show-protected">
            Protected
        </label>

        <label for="api-show-private" class="checkbox">
            <input type="checkbox" id="api-show-private">
            Private
        </label>
        <label for="api-show-deprecated" class="checkbox">
            <input type="checkbox" id="api-show-deprecated">
            Deprecated
        </label>

    </form>

 -->
        <div class="apidocs">
            <div id="docs-main">
                <div class="content">
                    <div class="page-header">
    <h1>src\cmpage\model\area.js <small>File</small></h1>
</div>

<div class="file">
    <pre class="prettyprint linenums" id='src_code'>
&#x27;use strict&#x27;;
// +----------------------------------------------------------------------
// | CmPage [ 通用页面框架 ]
// +----------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0
// +----------------------------------------------------------------------
// | Author: defans &lt;defans@sina.cn&gt;
// +----------------------------------------------------------------------

/**
 业务模块配置和展示系统的 model 类，实现了cmpage的主要业务逻辑，包括PC端和移动端

 注意点 :
 1. 在业务模块主信息设置中配置实现类,如：cmpage/page 或 demo/customer，系统会调用该类来展现页面
 2. 具体的业务模块必须继承 cmpage/model/page.js 来增加新的逻辑
 3. 移动端、主从页、查找带回等页面都是从 cmpage/model/page.js 继承，具体的业务模块请适当选择基类
 4. 在其他模块如 demo 中可以配置新的数据库连接，实现了多数据库的应该
 5. 每个页面根据不同的HTML输出位置和处理数据的流程分成了若干方法，子类中通过重写相应的方法可以达到定制页面的效果

 @module cmpage.model
 */

/**
 * 全国行政区划的操作类，如果内容作调整后，手机端APP部分也应该做调整，因为数据是预存在APP端的
 * @class cmpage.model.area
 */
export default class extends think.model.base {

    /**
     * 取省份记录， 缓存, 可以用于页面模块配置中的‘下拉框选择’调用: cmpage/area:getProvinces
     * @method  getProvinces
     * @return {Array}  省份记录列表
     */
    async getProvinces(){
        return await think.cache(&#x60;provinces&#x60;, () =&gt; {
            return this.query(&#x60;select * from t_area where c_pid =0 order by c_ucode&#x60;);
        });
    }

    /**
     * 根据省份编码取省份名称，一般用于页面模块配置中的‘替换’调用: cmpage/area:getProvinceName
     * @method  getProvinceName
     * @return {string}  名称
     * @param {string} province  编码
     */
    async getProvinceName(province){
        if(think.isEmpty(province)){
            return &#x27;&#x27;;
        }
        let provinces = await this.getProvinces();
        for(let item of provinces){
            if(item.c_ucode == province){
                return item.c_name;
            }
        }
        return &#x27;&#x27;;
    }

    /**
     * 根据城市编码取城市名称，一般用于页面模块配置中的‘替换’调用: cmpage/area:getCityName
     * @method  getCityName
     * @return {string}  名称
     * @param {string} city  编码
     */
    async getCityName(city){
        if(think.isEmpty(city)){
            return &#x27;&#x27;;
        }
        let citys = await this.getCitys(city.substr(0,2)+&#x27;0000&#x27;);
        for(let item of citys){
            if(item.c_ucode == city){
                return item.c_name;
            }
        }
        return &#x27;&#x27;;
    }

    /**
     * 根据区县编码取区县名称，一般用于页面模块配置中的‘替换’调用: cmpage/area:getCountryName
     * @method  getCountryName
     * @return {string}  名称
     * @param {string} country  编码
     */
    async getCountryName(country){
        if(think.isEmpty(country)){
            return &#x27;&#x27;;
        }
        let countrys = await this.getCountrys(country.substr(0,4)+&#x27;00&#x27;);
        for(let item of countrys){
            if(item.c_ucode == country){
                return item.c_name;
            }
        }
        return &#x27;&#x27;;
    }

    /**
     * 取城市记录， 缓存, 可以用于页面模块配置中的‘下拉框选择’调用: cmpage/area:getCitys
     * @method  getCitys
     * @return {Array}  城市记录列表
     * @param {string} province  省份编码
     */
    async getCitys(province){
        return await think.cache(&#x60;city${province}&#x60;, () =&gt; {
            return this.query(&#x60;select * from t_area where c_pid in(select id from t_area where c_ucode=&#x27;${province}&#x27;) order by c_ucode&#x60;);
        });
    }

    /**
     * 取区县记录， 缓存, 可以用于页面模块配置中的‘下拉框选择’调用: cmpage/area:getCountrys
     * @method  getCountrys
     * @return {Array}  区县记录列表
     * @param {string} province  城市编码
     */
    async getCountrys(city){
        return await think.cache(&#x60;country${city}&#x60;, () =&gt; {
            return this.query(&#x60;select * from t_area where c_pid in(select id from t_area where c_ucode=&#x27;${city}&#x27;) order by c_ucode&#x60;);
        });
    }

    /**
     * 取省份信息，组成省份选择的下拉项HTML
     * @method  getProvinceItems
     * @return {string}  下拉项的HTML片段
     * @param {string} value  省份编码，当前值
     * @param {bool} hasEmptyItem  是否有空项，一般查询HTML输出时用到
     */
    async getProvinceItems(value,hasEmptyItem){
        let html = [];
        value = think.isEmpty(value) ? &#x27;-1&#x27;: value;
        if(hasEmptyItem){
            html.push(&#x60;&lt;option value=&quot;-1&quot; ${value ==&quot;-1&quot; ? &quot;selected&quot;:&quot;&quot;}&gt;请选择&lt;/option&gt;&#x60;);
        }
        let provinces = await this.getProvinces();
        for(let item of provinces){
            html.push(&#x60;&lt;option value=&quot;${item.c_ucode}&quot; ${item.c_ucode == value ? &quot;selected&quot;:&quot;&quot;}&gt;${item.c_name}&lt;/option&gt;&#x60;);
        }
        return html.join(&#x27;&#x27;);
    }

    /**
     * 取城市信息，组成城市选择的下拉项HTML
     * @method  getCityItems
     * @return {string}  下拉项的HTML片段
     * @param {string} value  城市编码，当前值
     * @param {bool} hasEmptyItem  是否有空项，一般查询HTML输出时用到
     * @param {string} provinceValue  当前省份编码
     */
    async getCityItems(value,hasEmptyItem,provinceValue){
        let html = [];
        value = think.isEmpty(value) ? &#x27;-1&#x27;: value;
        if(hasEmptyItem){
            html.push(&#x60;&lt;option value=&quot;-1&quot; ${value ==&quot;-1&quot; ? &quot;selected&quot;:&quot;&quot;}&gt;请选择&lt;/option&gt;&#x60;);
        }
        let province = think.isEmpty(provinceValue) ? &#x27;&#x27;:provinceValue;
        if(!think.isEmpty(value) &amp;&amp; value !== &#x27;-1&#x27;){
            province = value.substring(0,2)+&#x27;0000&#x27;;
        }
        let citys = await this.getCitys(province);
        for(let item of citys){
            html.push(&#x60;&lt;option value=&quot;${item.c_ucode}&quot; ${item.c_ucode == value ? &quot;selected&quot;:&quot;&quot;}&gt;${item.c_name}&lt;/option&gt;&#x60;);
        }
        return html.join(&#x27;&#x27;);
    }

    /**
     * 取区县信息，组成区县选择的下拉项HTML
     * @method  getCountryItems
     * @return {string}  下拉项的HTML片段
     * @param {string} value  城市编码，当前值
     * @param {bool} hasEmptyItem  是否有空项，一般查询HTML输出时用到
     * @param {string} cityValue  当前城市编码
     */
    async getCountryItems(value,hasEmptyItem,cityValue){
        let html = [];
        value = think.isEmpty(value) ? &#x27;-1&#x27;: value;
        if(hasEmptyItem){
            html.push(&#x60;&lt;option value=&quot;-1&quot; ${value ==&quot;-1&quot; ? &quot;selected&quot;:&quot;&quot;}&gt;请选择&lt;/option&gt;&#x60;);
        }
        let city =think.isEmpty(cityValue) ? &#x27;&#x27;:cityValue;
        if(!think.isEmpty(value) &amp;&amp; value !== &#x27;-1&#x27;){
            city = value.substring(0,4)+&#x27;00&#x27;;
        }
        let countrys = await this.getCountrys(city);
        for(let item of countrys){
            html.push(&#x60;&lt;option value=&quot;${item.c_ucode}&quot; ${item.c_ucode == value ? &quot;selected&quot;:&quot;&quot;}&gt;${item.c_name}&lt;/option&gt;&#x60;);
        }
        return html.join(&#x27;&#x27;);
    }

}

    </pre>
</div>

                </div>
            </div>
        </div>
    </div>
<a id="gotoTop" class='well well-small' href='#'>
    Top
</a>
<script src="../assets/vendor/jquery/jquery-1.8.2.min.js"></script>
<script src="../assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script src="../assets/js/config.js"></script>
<script src="../assets/js/doc.js"></script>
</body>
</html>
